<?php

/**
 * Servicio filter form base class.
 *
 * @package    toyomotor
 * @subpackage filter
 * @author     Ing. Roberto Hernández De La Luz at Netosfera
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseServicioFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'nombre'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'kms_inicial'     => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'kms_periodico'   => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'intervalo_meses' => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'status'          => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'tipo_vehiculo'   => new sfWidgetFormChoice(array('choices' => array('' => '', 'Comercial' => 'Comercial', 'Carga' => 'Carga', 'Pasajeros' => 'Pasajeros', 'Comercial y Carga' => 'Comercial y Carga', 'Todos' => 'Todos'))),
      'servicios_list'  => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Cita')),
    ));

    $this->setValidators(array(
      'nombre'          => new sfValidatorPass(array('required' => false)),
      'kms_inicial'     => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'kms_periodico'   => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'intervalo_meses' => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'status'          => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'tipo_vehiculo'   => new sfValidatorChoice(array('required' => false, 'choices' => array('Comercial' => 'Comercial', 'Carga' => 'Carga', 'Pasajeros' => 'Pasajeros', 'Comercial y Carga' => 'Comercial y Carga', 'Todos' => 'Todos'))),
      'servicios_list'  => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Cita', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('servicio_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addServiciosListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.ServiciosCita ServiciosCita')
      ->andWhereIn('ServiciosCita.id_cita', $values)
    ;
  }

  public function getModelName()
  {
    return 'Servicio';
  }

  public function getFields()
  {
    return array(
      'id_servicio'     => 'Number',
      'nombre'          => 'Text',
      'kms_inicial'     => 'Number',
      'kms_periodico'   => 'Number',
      'intervalo_meses' => 'Number',
      'status'          => 'Boolean',
      'tipo_vehiculo'   => 'Enum',
      'servicios_list'  => 'ManyKey',
    );
  }
}
